package com.system.manager.modules.risk.controller;


import com.system.manager.common.annotation.PreAuthorize;
import com.system.manager.common.entity.PageDTO;
import com.system.manager.common.entity.Result;
import com.system.manager.common.exception.SysException;
import com.system.manager.modules.authorized.entity.User;
import com.system.manager.modules.authorized.enums.SubjectType;
import com.system.manager.modules.risk.entity.RiskType;
import com.system.manager.modules.risk.entity.TbFile;
import com.system.manager.modules.risk.service.ITbFileService;
import com.system.manager.utils.FileUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yxp
 * @since 2021-11-23
 */
@Slf4j
@Api(tags = "文件管理")
@RestController
@RequestMapping("/risk/tb-file/")
public class TbFileController {

    @Autowired
    private ITbFileService iTbFileService;

    @ApiOperation("查看所有文件")
    @PreAuthorize({SubjectType.SYSTEM_ADMIN,SubjectType.RISK_ADMIN})
    @GetMapping("list")
    public PageDTO riskFile(@RequestParam(name = "page", required = false, defaultValue = "1")Integer page,
                               @RequestParam(name = "limit", required = false, defaultValue = "10")Integer size) {

            // 获取所有的风险类型
            PageDTO<TbFile> pageDTO = iTbFileService.selectFiles(page, size);

            return pageDTO;
    }
    @ApiOperation("修改文件状态")
    @PreAuthorize({SubjectType.SYSTEM_ADMIN,SubjectType.RISK_ADMIN})
    @GetMapping("updateState")
    public void updateState(Integer fileId){
        iTbFileService.updateState(fileId);

    }

    //上传文件
    @PreAuthorize({SubjectType.SYSTEM_ADMIN, SubjectType.ENTERPRISE_ADMIN,SubjectType.RISK_ADMIN})
    @PostMapping("upLoad")
    @ApiOperation("导入文件信息")
    public Result upLoadFile(@RequestParam("file") MultipartFile file){

        String path = iTbFileService.upLoadFile(file);
        return Result.ok(path);
    }

}
